// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: gekim

#pragma once

#include <memory>
#include <string>

#include "coin2/exchange/base/symbology/currency.h"
#include "coin2/exchange/binance/symbology/currency.h"
#include "coin2/exchange/base/symbology/util.h"

using namespace coin2::exchange::binance::symbology;
namespace coin2::exchange::binance_us::symbology {

class BinanceUsCurrency
    : public base::symbology::Currency,
      public base::symbology::CurrencyFromStrMixin<BinanceUsCurrency> {
 public:
  using ExchangeType = base::market::ExchangeType;
  using MarketType = base::market::MarketType;
  using Currency = base::symbology::Currency;
  using base::symbology::Currency::native_currency;

 public:
  explicit BinanceUsCurrency(const std::string& currency)
      : Currency(currency, BinanceCurrency::ToNativeCurrency(currency).value(),
                 ExchangeType::Binanceus) {}

  static std::unique_ptr<BinanceUsCurrency> FromNativeStrImpl(
      const std::string& native_currency_str, int64_t resolve_timestamp) {
    auto currency = BinanceCurrency::FromNativeCurrencyFutures(
        native_currency_str, resolve_timestamp);
    if (currency) {
      return std::make_unique<BinanceUsCurrency>(currency.value());
    }
    return {};
  }

  static std::unique_ptr<BinanceUsCurrency> FromNormStrImpl(
      const std::string& currency_str, int64_t resolve_timestamp) {
    auto native_currency = BinanceCurrency::ToNativeCurrency(currency_str);
    if (!native_currency) {
      return {};
    }

    auto norm_currency = BinanceCurrency::FromNativeCurrencyFutures(*native_currency, resolve_timestamp);
    if (!norm_currency) {
      return {};
    }
    return std::make_unique<BinanceUsCurrency>(norm_currency.value());
  }
};
}  // namespace coin2::exchange::binance_us::symbology
